﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace HengTong.DataAccess.Migrations
{
    /// <inheritdoc />
    public partial class 新增采购申请单 : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "SysPurchaseRequestBill",
                columns: table => new
                {
                    ID = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    Applicant = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    RequestDate = table.Column<DateTime>(type: "datetime2", nullable: true),
                    NeedDate = table.Column<DateTime>(type: "datetime2", nullable: true),
                    PurchaseType = table.Column<int>(type: "int", nullable: true),
                    MaterialType = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    PurchaseMethod = table.Column<int>(type: "int", nullable: false),
                    UrgencyLevel = table.Column<int>(type: "int", nullable: true),
                    UrgencyReason = table.Column<string>(type: "nvarchar(1024)", maxLength: 1024, nullable: true),
                    Amount = table.Column<decimal>(type: "decimal(18,6)", nullable: true),
                    CreateTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    CreateBy = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: true),
                    UpdateTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    UpdateBy = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: true),
                    Approver = table.Column<string>(type: "nvarchar(64)", maxLength: 64, nullable: true),
                    ApprovalTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    GroupId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    OrgId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    BillCode = table.Column<string>(type: "nvarchar(128)", maxLength: 128, nullable: false),
                    BillStatus = table.Column<int>(type: "int", nullable: true),
                    WorkflowStatus = table.Column<int>(type: "int", nullable: true),
                    Remark = table.Column<string>(type: "nvarchar(512)", maxLength: 512, nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_SysPurchaseRequestBill", x => x.ID);
                    table.ForeignKey(
                        name: "FK_SysPurchaseRequestBill_FrameworkGroups_GroupId",
                        column: x => x.GroupId,
                        principalTable: "FrameworkGroups",
                        principalColumn: "ID");
                    table.ForeignKey(
                        name: "FK_SysPurchaseRequestBill_SysOrg_OrgId",
                        column: x => x.OrgId,
                        principalTable: "SysOrg",
                        principalColumn: "ID");
                });

            migrationBuilder.CreateTable(
                name: "SysPurchaseRequestBillEntry",
                columns: table => new
                {
                    ID = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    BillId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    MaterialId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    MaterialSkuId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    IsBackupMaterial = table.Column<bool>(type: "bit", nullable: false),
                    RequestQuantity = table.Column<decimal>(type: "decimal(18,6)", nullable: false),
                    UnitPrice = table.Column<decimal>(type: "decimal(18,6)", nullable: false),
                    TotalAmount = table.Column<decimal>(type: "decimal(18,6)", nullable: false),
                    BudgetAmount = table.Column<decimal>(type: "decimal(18,6)", nullable: true),
                    TechnicalRequirement = table.Column<string>(type: "nvarchar(1024)", maxLength: 1024, nullable: true),
                    RequiredArrivalDate = table.Column<DateTime>(type: "datetime2", nullable: true),
                    PurchaseProgress = table.Column<int>(type: "int", nullable: true),
                    CreateTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    CreateBy = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: true),
                    UpdateTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    UpdateBy = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: true),
                    Approver = table.Column<string>(type: "nvarchar(64)", maxLength: 64, nullable: true),
                    ApprovalTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    GroupId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    OrgId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    BillCode = table.Column<string>(type: "nvarchar(128)", maxLength: 128, nullable: false),
                    BillStatus = table.Column<int>(type: "int", nullable: true),
                    WorkflowStatus = table.Column<int>(type: "int", nullable: true),
                    Remark = table.Column<string>(type: "nvarchar(512)", maxLength: 512, nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_SysPurchaseRequestBillEntry", x => x.ID);
                    table.ForeignKey(
                        name: "FK_SysPurchaseRequestBillEntry_FrameworkGroups_GroupId",
                        column: x => x.GroupId,
                        principalTable: "FrameworkGroups",
                        principalColumn: "ID");
                    table.ForeignKey(
                        name: "FK_SysPurchaseRequestBillEntry_SysMaterialSku_MaterialSkuId",
                        column: x => x.MaterialSkuId,
                        principalTable: "SysMaterialSku",
                        principalColumn: "ID");
                    table.ForeignKey(
                        name: "FK_SysPurchaseRequestBillEntry_SysMaterial_MaterialId",
                        column: x => x.MaterialId,
                        principalTable: "SysMaterial",
                        principalColumn: "ID");
                    table.ForeignKey(
                        name: "FK_SysPurchaseRequestBillEntry_SysOrg_OrgId",
                        column: x => x.OrgId,
                        principalTable: "SysOrg",
                        principalColumn: "ID");
                    table.ForeignKey(
                        name: "FK_SysPurchaseRequestBillEntry_SysPurchaseRequestBill_BillId",
                        column: x => x.BillId,
                        principalTable: "SysPurchaseRequestBill",
                        principalColumn: "ID");
                });

            migrationBuilder.CreateTable(
                name: "SysPurchaseRequestBillFile",
                columns: table => new
                {
                    ID = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    BillId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    FileId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    Order = table.Column<int>(type: "int", nullable: false),
                    CreateTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    CreateBy = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: true),
                    UpdateTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    UpdateBy = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_SysPurchaseRequestBillFile", x => x.ID);
                    table.ForeignKey(
                        name: "FK_SysPurchaseRequestBillFile_FileAttachments_FileId",
                        column: x => x.FileId,
                        principalTable: "FileAttachments",
                        principalColumn: "ID");
                    table.ForeignKey(
                        name: "FK_SysPurchaseRequestBillFile_SysPurchaseRequestBill_BillId",
                        column: x => x.BillId,
                        principalTable: "SysPurchaseRequestBill",
                        principalColumn: "ID");
                });

            migrationBuilder.CreateTable(
                name: "SysPurchaseRequestBillEntryFile",
                columns: table => new
                {
                    ID = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    EntryId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    FileId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    Order = table.Column<int>(type: "int", nullable: false),
                    CreateTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    CreateBy = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: true),
                    UpdateTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    UpdateBy = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_SysPurchaseRequestBillEntryFile", x => x.ID);
                    table.ForeignKey(
                        name: "FK_SysPurchaseRequestBillEntryFile_FileAttachments_FileId",
                        column: x => x.FileId,
                        principalTable: "FileAttachments",
                        principalColumn: "ID");
                    table.ForeignKey(
                        name: "FK_SysPurchaseRequestBillEntryFile_SysPurchaseRequestBillEntry_EntryId",
                        column: x => x.EntryId,
                        principalTable: "SysPurchaseRequestBillEntry",
                        principalColumn: "ID");
                });

            migrationBuilder.CreateIndex(
                name: "IX_SysPurchaseRequestBill_GroupId",
                table: "SysPurchaseRequestBill",
                column: "GroupId");

            migrationBuilder.CreateIndex(
                name: "IX_SysPurchaseRequestBill_OrgId",
                table: "SysPurchaseRequestBill",
                column: "OrgId");

            migrationBuilder.CreateIndex(
                name: "IX_SysPurchaseRequestBillEntry_BillId",
                table: "SysPurchaseRequestBillEntry",
                column: "BillId");

            migrationBuilder.CreateIndex(
                name: "IX_SysPurchaseRequestBillEntry_GroupId",
                table: "SysPurchaseRequestBillEntry",
                column: "GroupId");

            migrationBuilder.CreateIndex(
                name: "IX_SysPurchaseRequestBillEntry_MaterialId",
                table: "SysPurchaseRequestBillEntry",
                column: "MaterialId");

            migrationBuilder.CreateIndex(
                name: "IX_SysPurchaseRequestBillEntry_MaterialSkuId",
                table: "SysPurchaseRequestBillEntry",
                column: "MaterialSkuId");

            migrationBuilder.CreateIndex(
                name: "IX_SysPurchaseRequestBillEntry_OrgId",
                table: "SysPurchaseRequestBillEntry",
                column: "OrgId");

            migrationBuilder.CreateIndex(
                name: "IX_SysPurchaseRequestBillEntryFile_EntryId",
                table: "SysPurchaseRequestBillEntryFile",
                column: "EntryId");

            migrationBuilder.CreateIndex(
                name: "IX_SysPurchaseRequestBillEntryFile_FileId",
                table: "SysPurchaseRequestBillEntryFile",
                column: "FileId");

            migrationBuilder.CreateIndex(
                name: "IX_SysPurchaseRequestBillFile_BillId",
                table: "SysPurchaseRequestBillFile",
                column: "BillId");

            migrationBuilder.CreateIndex(
                name: "IX_SysPurchaseRequestBillFile_FileId",
                table: "SysPurchaseRequestBillFile",
                column: "FileId");
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "SysPurchaseRequestBillEntryFile");

            migrationBuilder.DropTable(
                name: "SysPurchaseRequestBillFile");

            migrationBuilder.DropTable(
                name: "SysPurchaseRequestBillEntry");

            migrationBuilder.DropTable(
                name: "SysPurchaseRequestBill");
        }
    }
}
